package com.jwaoo.mobile.view.register.fragment;

import android.content.Context;
import android.support.annotation.IdRes;
import android.view.View;
import android.widget.RadioGroup;

import com.dx.as.ToolBarOptions;
import com.dx.as.common.FragmentUtils;
import com.dx.as.fragment.TFragment;
import com.jwaoo.mobile.R;
import com.jwaoo.mobile.view.register.IParamListener;
import com.jwaoo.mobile.view.register.presenter.IRegisterView;
import com.jwaoo.mobile.view.register.presenter.RegisterPresenter;
import java.util.Map;

/**
 * Created by jwaoo on 2017/10/16.
 */

public class SexFragment extends TFragment implements IRegisterView {

    private RegisterPresenter presenter;
    private IParamListener listener;
    private int gender = 1;//1男，2女

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        listener = (IParamListener)context;
    }

    @Override
    public void initView() {
        findView(R.id.btn_next).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Map map = listener.getParamMap();
                map.put("gender",gender);
                presenter.doRegister(map);
            }
        });
        ((RadioGroup)findView(R.id.group_sex)).setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, @IdRes int i) {
                if (i == R.id.radio_male){
                    gender = 1;
                }else {
                    gender = 2;
                }
            }
        });
        findView(R.id.btn_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                FragmentUtils.goBackFragment(getActivity(),HeadFragment.class,R.id.register_container,SexFragment.class);
            }
        });
    }

    @Override
    public int setLayoutI() {
        return R.layout.fragment_sex;
    }

    @Override
    public void dataOpion() {

    }

    @Override
    public void initRpo() {
        presenter = new RegisterPresenter(getActivity(),this);
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onSendEmail() {

    }

    @Override
    public void onRegisterSucess() {
        FragmentUtils.goToFragment(getActivity(),SuccessFragment.class,R.id.register_container);
    }
}
